# 项目：py-advance
# 文件：02查询
# 作者：Frank Gong
# 日期：2025/4/10 12:10
# coding:utf-8
import pymysql

# 创建连接
conn = pymysql.connect(host='localhost',port=3306,
                             user='root',password='12345678',
                             db='hotel',charset='utf8')
# 创建游标
cursor = conn.cursor()

# 查询语句
cursor.execute("select * from emp")
# 获取剩余结果的第一行数据
row_1 = cursor.fetchone()
print(row_1)
cursor.scroll(-1,'relative')
# 获取剩余结果前n行数据
row_2 = cursor.fetchmany(3)
print(row_2)
# 获取剩余结果所有数据
row_3 = cursor.fetchall()
print(row_3)
conn.commit()
cursor.close()
conn.close()
